"use strict";
cc._RF.push(module, 'dd9bfNz9UJB3bCBu1vWod7X', 'ScheduleCom');
// scripts/modes/normalMode/levelAvoid/base/ScheduleCom.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ScheduleCom = void 0;
/**定时触发组件 */
var ScheduleCom = /** @class */ (function () {
    function ScheduleCom() {
        this.funcs = [];
        this.isCreal = false;
    }
    ScheduleCom.prototype.update = function (dt) {
        if (this.isCreal) {
            this.funcs = [];
            this.isCreal = false;
            return;
        }
        if (this.funcs.length == 0)
            return;
        var temp = [];
        for (var i = 0; i < this.funcs.length; i++) {
            var element = this.funcs[i];
            if (element.isPause) {
                temp.push(element);
                continue;
            }
            if (element.nowTime <= 0) {
                element.cb();
                if (element.count <= -1) {
                    element.nowTime = element.interval;
                    temp.push(element);
                    continue;
                }
                element.count--;
                if (element.count > 0) {
                    element.nowTime = element.interval;
                    temp.push(element);
                }
            }
            else {
                temp.push(element);
            }
            element.nowTime -= dt;
        }
        this.funcs = temp;
    };
    ScheduleCom.prototype.add = function (cb, interval, count) {
        var temp = {
            cb: cb,
            interval: interval,
            nowTime: interval,
            count: (count) ? count : -1,
            isPause: false
        };
        this.funcs.push(temp);
        return temp;
    };
    ScheduleCom.prototype.clearAll = function () {
        this.funcs = [];
        this.isCreal = true;
    };
    return ScheduleCom;
}());
exports.ScheduleCom = ScheduleCom;

cc._RF.pop();